﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 开单
{
    class DataUtil
    {

        /// <summary>
        /// 取得当前时间到秒，"2010-10-10 23:40:34"
        /// </summary>
        /// <returns></returns>
        public static string GetStandardTimeBySecond()
        {
            DateTime dt = DateTime.Now.ToLocalTime();
            return dt.ToString("yyyy-MM-dd HH:mm:ss");
        }

        /// <summary>
        /// 将string值格式化为"2010-10-10 23:40:34"
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string FormatToStandard(string str)
        {
            DateTime dt = DateTime.Parse(str);
            return dt.ToString("yyyy-MM-dd HH:mm:ss");
        }

        /// <summary>
        /// 将TimeTiper值格式化为"2010-10-10 23:40:34"
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string FormatToStandard(DateTime dt)
        {

            return dt.ToString("yyyy-MM-dd HH:mm:ss");
        }

        /// <summary>
        /// 将TimeTiper值格式化为"20101010234034"
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string FormatToLong(DateTime dt)
        {
            return dt.ToString("yyyyMMddHHmmss");
        }

        /// <summary>
        /// 将TimeTiper值格式化为"20101010234034"
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static string FormatToLong(string str)
        {
            DateTime dt = DateTime.Parse(str);
            return dt.ToString("yyyyMMddHHmmss");
        }

        /// <summary>
        /// "2010-10"
        /// </summary>
        /// <returns></returns>
        public static string GetYearAndMonth()
        {
            DateTime dt = DateTime.Now;
            return dt.ToString("yyyy-MM");
        }

        /// <summary>
        /// "201010"
        /// </summary>
        /// <returns></returns>
        public static string GatYearAndMonth2()
        {
            DateTime dt = DateTime.Now;
            return dt.ToString("yyyyMM");
        }
    }
}
